#ifndef TEACHMODE_H
#define TEACHMODE_H

#include <QWidget>
#include "util/util.h"
#include <QTcpSocket>


namespace Ui {
class TeachMode;
}

class TeachMode : public QWidget
{
    Q_OBJECT

public:
    explicit TeachMode(QWidget *parent = 0);
    ~TeachMode();

    void changeLabelPageDisplay();
    void changeProgramEditAuthority();

signals:
    void returnMenu();
    void go2ProgramEditor_(QString buttonName);

private slots:
    void pushReturnMenu();

private:
    Ui::TeachMode *ui;
    SoftKeyboard *softKeyboard;
    QList<QPushButton *> createdButtons;
    QList<QPoint> deletedButtonsPositions;
    int* ProgramCategoryChosen;
    int* pageCount;
    int pageButton[10] = {1,1,1,
                          1,
                          1,1,1,
                          1,1,1};
    int pageProgram[4] = {0,0,0,0};
    int pageProgramCapacity[4] = {60,2,4,4};

    void addNewProgram();
    void deleteNewProgram();
    void setButton();
    void disableButton();
    QPushButton* createNewButton(const QString& buttonName, int currentPage);
    void connectNewButton(QPushButton* newButton);
    void calculateButtonPosition(int& currentPage, int& x, int& y);
    void setButtonGeometry(QPushButton* newButton, int x, int y);
    void handleButtonDeletion(QPushButton* buttonToDelete, int currentPageIndex);
    bool isValidButtonIndex(int index, int buttonCount);
    void loadSavedButtons();
    void saveButtonInfo(const QString& buttonName, int currentPage, int x, int y);
    bool isButtonNameUnique(const QString& buttonName);
    bool isButtonPositionUnique(int x, int y);
    bool isButtonCreated(QPushButton* button);
    bool connectToHost(QTcpSocket& tcpSocket, const QString& hostAddress, int port);
    void handlePageSwitch(int buttonIndex, int *pageCount, int* pagechose);
    void connectButtonsAndSignals();
    bool isReachCapacityLimit();
    int calculateInWhichPage(int& currentPage);
    bool eventFilter(QObject *watched, QEvent *event);
};

#endif // TEACHMODE_H
